package com.daydayup.learn;

public class ThreadGroupTest {

    public static void main(String[] args) {
        ThreadGroup group = Thread.currentThread().getThreadGroup();

        System.out.println("主线程组:"+group.getName());

        ThreadGroup javaGroup = new ThreadGroup("Java组");

        Thread t1 = new Thread(javaGroup, () -> {
            System.out.println("AAAAAAAAAAAAAAA");
            try {
                Thread.sleep(3000);
            } catch (Exception e) {
                e.printStackTrace();
            }
        });

        Thread t2 = new Thread(javaGroup, () -> {
            System.out.println("BBBBBBBBBBBBBBB");
            try {
                Thread.sleep(3000);
            } catch (Exception e) {
                e.printStackTrace();
            }
        });

        t1.start();
        t2.start();

        Thread[] threads = new Thread[javaGroup.activeCount()];
        javaGroup.enumerate(threads);
        for (Thread t : threads) {
            System.out.println(javaGroup.getName()+"组的线程:"+t.getName());
        }

        try {
            Thread.sleep(3000);
        } catch (Exception e) {
            e.printStackTrace();
        }
        javaGroup.interrupt();
    }
}
